﻿using Architecture.API.Application.Command.RequestForLeaveCommand;
using Architecture.Domain;
using Architecture.Domain.Service.LeaveServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.RequestForLeaveHandler
{
    /// <summary>
    /// 请假申请命令
    /// </summary>
    public class LeaveUpdateCommandHandler : IRequestHandler<LeaveUpdateCommand, int>
    {
        /// <summary>
        /// 请假服务
        /// </summary>
        protected readonly ILeaveService _leaveService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="leaveService">请假服务</param>
        public LeaveUpdateCommandHandler(ILeaveService leaveService)
        {
            _leaveService = leaveService;
        }

        /// <summary>
        /// 修改请假申请
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(LeaveUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _leaveService.UpdateLeave(new RequestForLeave() { LeaveId = request.LeaveId, UserName = request.UserName, DepartmentId = request.DepartmentId, LeaveType = request.LeaveType, LeaveStartTime = request.LeaveStartTime, LeaveEndTime = request.LeaveEndTime, TotalWorkTime = request.TotalWorkTime, RegistrationTime = request.RegistrationTime, SubjectMatter = request.SubjectMatter, DepartmentLeader = request.DepartmentLeader });
        }
    }
}
